import {h} from 'vue'
import {NTag, NAvatar} from 'naive-ui'
import type {StnDataTableColumns} from 'st-ui-vue3-navie'
import {StnTableOperationBtnGroup} from 'st-ui-vue3-navie'
import {UserType} from '@config'

/**
 * 用户信息表格列配置
 */
export const UserTableCols: StnDataTableColumns = [
  {
    type: 'selection',
    fixed: 'left',
    width: 40,
    checked: true,
  },
  {
    title: '头像',
    key: 'avatar',
    width: 60,
    checked: true,
    render: (row: UserType) => {
      return h(NAvatar, {
        size: 'small',
        src: row.avatar || undefined,
        round: true,
      })
    }
  },
  {
    title: '用户名',
    key: 'username',
    width: 120,
    checked: true,
  },
  {
    title: '昵称',
    key: 'nickname',
    width: 120,
    checked: true,
  },
  {
    title: '邮箱',
    key: 'email',
    width: 180,
    checked: true,
  },
  {
    title: '手机号',
    key: 'phone',
    width: 120,
    checked: true,
  },
  {
    title: '性别',
    key: 'gender',
    width: 80,
    checked: true,
    render: (row: UserType) => {
      const genderMap = {
        0: '未知',
        1: '男',
        2: '女'
      }
      return h(NTag, {
        type: 'info',
        round: true,
        bordered: false,
      }, {
        default: () => genderMap[row.gender as keyof typeof genderMap]
      })
    }
  },
  {
    title: '状态',
    key: 'status',
    width: 80,
    checked: true,
    render: (row: UserType) => {
      return h(NTag, {
        type: row.status === 1 ? 'success' : 'error',
        round: true,
        bordered: false,
      }, {
        default: () => row.status === 1 ? '启用' : '禁用'
      })
    }
  },
  {
    title: '排序',
    key: 'sort',
    width: 80,
    checked: true,
  },
  {
    title: '创建时间',
    key: 'createTime',
    width: 180,
    checked: true,
  },
  {
    title: '更新时间',
    key: 'updateTime',
    width: 180,
    checked: true,
  },
  {
    title: '创建人',
    key: 'createBy',
    width: 120,
    checked: true,
  },
  {
    title: '更新人',
    key: 'updateBy',
    width: 120,
    checked: true,
  },
  {
    title: '操作',
    key: 'operation',
    width: 120,
    fixed: 'right',
    checked: true,
    render: (row: UserType) => {
      return h(StnTableOperationBtnGroup, {
        btns: [
          {
            type: 'edit',
            onClick: () => {
              // 编辑用户信息
              window.$showUserInfoEditor?.(row)
            }
          },
          {
            type: 'del',
            onClick: () => {
              // 删除用户信息
              window.$showUserDelConfirm?.([row.id])
            }
          }
        ]
      })
    }
  }
] 